package mysql

import (
	"gorm.io/gorm"
	"novel-sys/goods/goods"
)

type Comment struct {
	gorm.Model
	UserId  int64  `gorm:"type:int(11)"`
	NovelId int64  `gorm:"type:int(11)"`
	Comment string `gorm:"type:varchar(50)"`
}

func (c *Comment) CommentAdd(db *gorm.DB) error {
	return db.Debug().Create(c).Error
}
func CommentList(db *gorm.DB, id int64) []*goods.CommentList {
	var data []*goods.CommentList
	db.Debug().Model(&Comment{}).Select(
		"comments.`comment`",
		"users.nick_name",
		"users.head_image").
		Joins(" LEFT JOIN users ON users.id = comments.user_id").
		Where("comments.novel_id=?", id).
		Find(&data)
	return data
}
